<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Order extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $order_data = $this->input->post('user', TRUE);
        $return['order_id'] = time();
        $return['time'] = time();
        $return['message'] = $order_data . '订单写入成功';
        str_alert(200, 'success', $return);
    }

    public function add()
    {
        $data = $this->input->post('data');
        $openid = $this->input->post('openid');
        if (empty($data)) {
            str_alert(400, 'error');
        }
        $return_order = rsa_decrypt($data, $openid);//解密
        if (empty($return_order)) {
            str_alert(400, '未授权');
        }
        str_alert(200, 'success', $return_order);
    }

    public function test()
    {
        $order['order_id'] = 123;
        $order['order_time'] = time();
        $order['order_data'] = 123;
        $order['openid'] = 15325136818;
        $openid = $this->input->post('openid');

        $data = rsa_encrypt($order, $openid);//加密
        print_r($data);
        $return_order = rsa_decrypt($data);//解密
        str_alert(200, 'success', $return_order);
        $return['order_id'] = time();
        $return['time'] = time();
        $return['message'] = '订单写入成功';
        str_alert(200, 'success', $data);
    }

}